package com.sy.simpleegg.mvp.presenter

import androidx.lifecycle.LifecycleCoroutineScope
import com.sy.simpleegg.base.BasePresenter
import com.sy.simpleegg.mvp.contract.UpgradeContract
import com.sy.simpleegg.mvp.model.UpgradeModel
import kotlinx.coroutines.launch

class UpgradePresenter(private val lifecycleCoroutineScope: LifecycleCoroutineScope): BasePresenter<UpgradeContract.Model,
        UpgradeContract.View>(), UpgradeContract.Presenter, UpgradeModel.DownloadListener {

    override fun createModel(): UpgradeContract.Model = UpgradeModel(this)
    override fun downloadApp(savePath: String, apkName: String, url: String) {
        lifecycleCoroutineScope.launch {
            mModel?.downloadApp(savePath, apkName, url)
        }
    }

    override fun downloadSuccess(path: String) {
        lifecycleCoroutineScope.launch {
            mView?.downloadSuccess(path)
        }
    }

    override fun failed(msg: String) {
        lifecycleCoroutineScope.launch {
            mView?.failed(msg)
        }
    }

    override fun refreshProgress(progress: Int) {
        lifecycleCoroutineScope.launch {
            mView?.refreshProgress(progress)
        }
    }

}